#include "Delegate.h"
#include <length.h>
#include <IPC/streamIO.h>
#include "PAL.h"

#define NOWT ((_tcb*)(run->mar))




  _ptlong DelegateOnThread(_tcb* delegated,_tcb* delegator)
  {
    MUTEX_LOCK(&(delegator->delegatesLocker));
    slnode* delegateds = delegator->delegates->delegated;
    if(delegateds == NULL)
      {//Initialize
	delegateds = delegator->delegates->delegated = MakeSListNode(_KMalloc(sizeof(slnode)),delegated);
      }
    else
      {
	InsertSListNode(delegateds,MakeSListNode(_KMalloc(sizeof(slnode)),delegated));
      }
    TaskSchedule(SCHEDULE_MUTEX);
    MUTEX_UNLOCK(&(delegator->delegatesLocker));
    return 1;
  }

  _ptlong DelegateOnFile(_tcb* delegated,_fstr delegator)
  {
    
  }

  _ptlong RunDelegatedThread(_tcb* dyingthread)
  {
    slnode* delegateds = delegator->delegates->delegated;
    
    while(delegateds != NULL)
      {
	RunThread(delegateds->mark);
	delegateds = delegateds->next;
      }
    return 1;
  }

  

